package tools

import (
	"github.com/gin-gonic/gin"
	"k8s-platform/service/tools"
	"net/http"
)

var Harbor_data harbor_data

type harbor_data struct{}

func (*harbor_data) Harbor_projects(c *gin.Context) {
	//p := new(struct {
	//	ID int64 `form:"id"`
	//})
	//if err := c.Bind(p); err != nil {
	//	c.JSON(http.StatusOK, gin.H{
	//		"code": 90400,
	//		"msg":  err.Error(),
	//		"data": nil,
	//	})
	//	return
	//}
	data, err := tools.Harbor_projects()
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 90500,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "查询Harbor项目列表成功",
		"data": data,
	})
}

func (*harbor_data) Harbor_prepositories(c *gin.Context) {
	p := new(struct {
		Projectname string `form:"projectname"`
	})
	if err := c.Bind(p); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 90400,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	data, err := tools.Harbor_prepositories(p.Projectname)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 90500,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "查询Harbor仓库列表成功",
		"data": data,
	})
}

func (*harbor_data) Harbor_images_list(c *gin.Context) {
	p := new(struct {
		Projectname string `form:"projectname"`
		ImagesName  string `form:"imagesname"`
	})
	if err := c.Bind(p); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 90400,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	data, err := tools.Harbor_images_list(p.Projectname, p.ImagesName)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 90500,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "查询Harbor版本列表成功",
		"data": data,
	})
}
